﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace App.Assistant
{
    public class GridViewSkin
    {
        public static void CssGridViewLength(GridView gv, int cloumCount, int[] eachLength)
        {
            for (int i = 0; i < eachLength.Length; i++)
            {
                gv.Columns[i].HeaderStyle.Width = eachLength[i]; // 自定义宽度
                gv.Columns[i].ItemStyle.Width = eachLength[i]; // 自定义宽度
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eachLength"></param>
        public static void CssGridViewLength(object sender, int[] eachLength)
        {
            GridView gv = (GridView)sender;
            for (int i = 0; i < eachLength.Length; i++)
            {
                gv.Columns[i].HeaderStyle.Width = eachLength[i]; // 自定义宽度
                gv.Columns[i].ItemStyle.Width = eachLength[i]; // 自定义宽度
            }
        }

        /// <summary>
        /// 统一设置GridView每一行和列的样式以及鼠标滑过效果
        /// 只需要调用该方法就可以了把sender和e传进来
        /// 写在Gridview的RowDataBound事件里 
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e"></param>
        public static void NormalCss(object sender, GridViewRowEventArgs e)
        {
            GridView gv = (GridView)sender;
            gv.CssClass = "main_listback01";
            gv.EmptyDataText = "暂无相关信息";
            for (int i = 0; i < gv.Columns.Count; i++)
            {
                if (i == 0)
                {
                    gv.Columns[i].ItemStyle.CssClass = "main_list_left01";
                    gv.Columns[i].HeaderStyle.CssClass = "main_list_left01";
                }
                else
                {
                    gv.Columns[i].ItemStyle.CssClass = "main_list_center01";
                    gv.Columns[i].HeaderStyle.CssClass = "main_list_center01";
                }
            }
            if (e.Row.RowType == DataControlRowType.Header)
            { e.Row.CssClass = "main_listmenu01"; }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onMouseOver", "this.className='main_list_onmouseover'");
                e.Row.Attributes.Add("onMouseOut", "this.className='main_list_onmouseout'");
            }
        }

        public static void NormalCss_Web(object sender, GridViewRowEventArgs e)
        {
            GridView gv = (GridView)sender;
            gv.EmptyDataText = "暂无相关信息";
            gv.Style.Add(HtmlTextWriterStyle.Width, "100%");
            if (e.Row.RowType == DataControlRowType.Header)
            {
                foreach (TableCell tc in e.Row.Cells)
                {
                    tc.CssClass = "huisekuang";
                    tc.Style.Add("background-color", "#FFFFCC");
                }
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
            }
        }
        /// <summary>
        /// 统一设置GridView每一行和列的样式以及鼠标滑过效果
        /// 只需要调用该方法就可以了把sender和e传进来
        /// 写在Gridview的RowDataBound事件里
        /// 拥有固定表头信息注在gridview外加一个div控制显示        
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void NormalCssHasHeader(object sender, GridViewRowEventArgs e)
        {
            GridView gv = (GridView)sender;
            gv.CssClass = "main_listback01";
            gv.EmptyDataText = "暂无相关信息";
            for (int i = 0; i < gv.Columns.Count; i++)
            {
                if (i == 0)
                {
                    gv.Columns[i].ItemStyle.CssClass = "main_list_left01";
                    gv.Columns[i].HeaderStyle.CssClass = "main_list_left01";
                }
                else
                {
                    gv.Columns[i].ItemStyle.CssClass = "main_list_center01";
                    gv.Columns[i].HeaderStyle.CssClass = "main_list_center01";
                }
            }
            if (e.Row.RowType == DataControlRowType.Header)
            { e.Row.CssClass = "main_listmenu01_has_header"; }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onMouseOver", "this.className='main_list_onmouseover'");
                e.Row.Attributes.Add("onMouseOut", "this.className='main_list_onmouseout'");
            }
        }

        /// <summary>
        ///权限格式控制
        /// </summary>
        /// <param name="e"></param>
        public static void PurviewCss(GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HtmlInputCheckBox cb = (HtmlInputCheckBox)e.Row.FindControl("chkV");
                Label tx = (Label)e.Row.FindControl("Label1");
                if (cb != null)//（和你的字段值比较）   
                {
                    if (cb.Visible == false)
                    {
                        //tx.Font.Bold = true;
                        e.Row.BackColor = System.Drawing.Color.PowderBlue;
                        if (tx != null)
                        {
                            e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Left;
                            tx.Font.Bold = true;
                        }
                    }
                }
            }
        }
    }
}